﻿using System;
using System.Web.Mvc;
using OASys.Biz.BizAccess;
using OASys.Enum;
using OASys.Web.Areas.ModuleExecutive.Models;
using OASys.Web.Base;
using Project.Common;
using Project.Web.Base;
using Project.Web.Base.Utility;

namespace OASys.Web.Areas.ModuleExecutive.Controllers
{
    /// <summary>
    /// 请假申请
    /// </summary>
    public class ApplyHolidayController : BaseController
    {
        private BizUTApplyHoliday bizUTApplyHoliday;

        public ActionResult Index(ModelApplyHolidayIndex model, ExportHelper export)
        {
            model.ExportObject = export;
            model.RetriveData();
            return View(model);
        }

        /// <summary>
        /// 创建 修改 查看
        /// </summary>
        public ActionResult Create(ModelApplyHolidayCreate model)
        {
            ViewBag.PageState = model.PageState;
            model.RetriveData();
            return View(model);
        }

        /// <summary>
        /// 创建 修改 查看
        /// </summary>
        [HttpPost]
        public ActionResult Create(ModelApplyHolidayCreate model, FormCollection collection)
        {
            try
            {
                model.Save();
                return Content(WebTools.ScriptCloseDialog(DialogOption.GetDefaultInstance()));
            }
            catch
            {
                //操作失败！
                Error = OASys.Resources.Properties.Resources.M00002E;
                model.RetriveData();
                return View(model);
            }
        }

        /// <summary>
        /// 根据主键删除
        /// </summary>
        [HttpPost]
        public ActionResult Delete(Guid id)
        {
            JsonResult jsresult = new JsonResult();
            jsresult.ContentType = Consts.CONTENT_TYPE;
            jsresult.Data = new { result = string.Empty };
            try
            {
                bizUTApplyHoliday.DeleteByID(id, NHibernate.NHibernateUtil.Guid);
                jsresult.Data = new { result = string.Empty };
            }
            catch
            {
                //此条申请已经再审批中，暂时不能删除
                jsresult.Data = new { result = OASys.Resources.Properties.Resources.M10007E };
            }
            return jsresult;
        }
    }
}
